#include <stdio.h>
#include <stdlib.h>

int main (int argc, char const* argv[])
{

    int n, i, j;

    while (scanf("%d", &n) && n) {
        int sign = 0;
        char c[30];
        int base[17] = {0};
        for (i = 2; i <= 16; i++) {
            int m = n;
            int len = 0;
            while (m) {
                c[len++] = m % i;
                m = m / i;
            }

            sign = 1;
            for (j = 0; j < len/2 && sign; j++) {
                if (c[j] != c[len-j-1]) {
                    sign = 0;
                }
            }
            if (sign) {
                base[i] = 1;
            }
        }
        sign = 1;

        for (i = 2; i <= 16; i++) {
            if (base[i] == 1) {
                sign = 0;
            }
        }
        if (sign) {
            printf("Number %d is not a palindrom\n", n);
        } else {
            printf("Number %d is palindrom in basis", n);
            for (i = 2; i <= 16; i++) {
                if (base[i] == 1) {
                    printf(" %d", i);
                }
            }
            printf("\n");
        }
    }

    return 0;
}
